import { Application } from "egg";
import { Lockers } from "./lockers";

/**
 * 储物柜基础http api接口封装, 不含具体业务逻辑
 */
export default class CodoLockersBaseInterface {
	constructor(private app: Application) {}
	/** 获取柜子信息
	 * @param {string} addr 设备地址 i.e. 127.0.0.1:9000
	 */
	async getInfo(addr: string) {
		const fullPath = `${addr}/getCabinetInfo`;
		const res = await this.app.curl<Lockers.Response.GetCabinetInfo>(fullPath, {
			dataType: "json",
			method: "GET",
			headers: {
				"content-type": "multipart/form-data",
			},
		});
		return res.data;
	}
	/** 获取柜子状态
	 * @param {string} addr 设备地址 i.e. 127.0.0.1:9000
	 */
	async getState(addr: string) {
		const fullPath = `${addr}/getCabinetState`;
		const res = await this.app.curl<Lockers.Response.GetCabinetState>(fullPath, {
			method: "GET",
			dataType: "json",
			headers: {
				"content-type": "multipart/form-data",
			},
		});
		return res.data;
	}
}
